"use strict";

/**
 * 上课情况相关接口调用
 */
import Ajax from "../libs/ajax";

//导入课表
export function importSchedule(data) {
    return Ajax.ajax({
        url: '/api/schedule/import_schedule',
        method: 'post',
        data: data
    }).then(res => res.data)
}

//删除课表
export function deleteSchedule(data) {
    return Ajax.ajax({
        url: '/api/schedule/delete_schedule',
        method: 'post',
        data: data
    }).then(res => res.data)
}

// 获取课表
export function getSchedule(query={}) {
    const baseUrl = "/api/schedule/query";
    if (query.page_num === undefined || query.page_size === undefined) {
        return new Promise((resolve, reject) => {
            resolve({ code: 2011, msg: "课表查询参数缺失" });
        });
    }
    return Ajax.ajax({
        url: baseUrl,
        method: "post",
        data: query
    }).then(res => res.data);
}

// 绑定教室
export function bindClassroom(data) {
    const baseUrl = "/api/schedule/bind_classroom";
    if (!data.schedule_id || !data.classroom_id) {
        return new Promise((resolve, reject) => {
            resolve({ code: 2011, msg: "参数缺失" });
        });
    }
    return Ajax.ajax({
        url: baseUrl,
        method: "post",
        timeout: 1 * 60 * 1000,
        data
    }).then(res => res.data);
}